package com.wei.shopping.controller;

import com.wei.shopping.entrty.PageResult;
import com.wei.shopping.entrty.QueryPageBean;
import com.wei.shopping.entrty.Result;
import com.wei.shopping.service.CollectService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @Author Wei
 * @Date 2021/4/29 14:11
 */
@RestController
@RequestMapping("/collect")
public class CollectController {

    @Resource
    private CollectService collectService;
    /**
     * 删除收藏
     * @param id
     * @return
     */
    @GetMapping("/delcollect/{id}")
    public Result delCollect(@PathVariable("id") String id){
        try{
            collectService.delcollect(id);
            return new Result(true,"删除成功");
        }catch(Exception e){
            e.printStackTrace();
            return new Result(false,"删除失败，请重试");
        }
    }
    @PostMapping("/collectFindAll")
    public PageResult collectFindAll(@RequestBody QueryPageBean queryPageBean, HttpSession session){
        PageResult pageResult = null;
        try{
            String userid =(String) session.getAttribute("userid");
            pageResult = collectService.collectFindAll(queryPageBean,userid);
            return pageResult;
        }catch(Exception e){
            e.printStackTrace();
            return pageResult;
        }
    }
}
